<?php

    function fileds_row_array($row_array, $column, $prefix = 'object_') {

        if (!isset($row_array[$column]))
            return $row_array;

        $fields = unserialize($row_array[$column]);

        foreach ($fields as $key => $value) {

            $pices = explode("___", $key);

            switch ($pices[1]) {

                case "search_priority":

                    if ($value == "") {

                        $row_array[$prefix . $pices[1]] = 999;
                    } else {

                        $row_array[$prefix . $pices[1]] = $value;
                    }


                    break;

                default :
                    $row_array[$prefix . $pices[1]] = $value;
            }
        }

        unset($row_array[$column]);

        return $row_array;
    }

    function fileds_result_array($res_array, $column) {
        $cnt = count($res_array);

        for ($i = 0; $i < $cnt; $i++) {
            $res_array[$i] = fileds_row_array($res_array[$i], 'object_fields');
        }

        return $res_array;
    }

    function filter_additional($row_array) {

        $fields = unserialize($row_array);
        $additional = array();

        foreach ($fields as $key => $value) {
            if ($value != "" && $value != " ")
                $additional[substr($key, 4)] = $value;
        }

        //unset fileds wtih uniterested value
        if (isset($additional['exterior']) && ($additional['exterior'] == '0'))
            unset($additional['exterior']);

        // unset used fields
        if (isset($additional['title']))
            unset($additional['title']);
        if (isset($additional['short_description']))
            unset($additional['short_description']);
        if (isset($additional['surface']))
            unset($additional['surface']);
        if (isset($additional['price']))
            unset($additional['price']);
        if (isset($additional['x_coordinate']))
            unset($additional['x_coordinate']);
        if (isset($additional['y_coordinate']))
            unset($additional['y_coordinate']);

        return $additional;
    }
    